package aca

import java.util.Map;

class ProfessorController {

	def index() {

	}

	def create = {
	if (Verifica.verificaAdm(session.openidParams.ax.get("email").toString())){
     def professorInstance = new Professor()
        professorInstance.properties = params
        return [professorInstance: professorInstance]
	}else{
		redirect(controller:"user",action:"proibido")
		}
	}
	
	def save = {
		if (Verifica.verificaAdm(session.openidParams.ax.get("email").toString())){
		def professorInstance = new Professor(params)
		if (professorInstance.save(flush: true)) {
			flash.message = "${message(code: 'default.created.message', args: [message(code: 'professor.label', default: 'Professor'), professorInstance.id])}"
			redirect(action: "show", id: professorInstance.id)
		}
		else {
			render(view: "create", model: [professorInstance: professorInstance])
		}
		}else{
		redirect(controller:"user",action:"proibido")
		}
		
	}
	
	def show = {
		if (Verifica.verificaAdm(session.openidParams.ax.get("email").toString())){
		def professorInstance = Professor.get(params.id)
		if (!professorInstance) {
			flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'professor.label', default: 'Professor'), params.id])}"
			redirect(action: "list")
		}
		else {
			[professorInstance: professorInstance]
		}
		}else{
		redirect(controller:"user",action:"proibido")
		}
	}

	def list() {
		if (Verifica.verificaAdm(session.openidParams.ax.get("email").toString())){
		[professorInstanceTotal: Professor.count(),
					professorInstanceList: Professor.list()]
		}else{
		redirect(controller:"user",action:"proibido")
		}
	}

//	def save() {
//		def professorInstance = new Professor(params)
//		if (!professorInstance.save(flush: true)) {
//			render view: 'create', model: [Professor: Professor]
//			return
//		}
//	}
	private String extraiDados(Map mapa){
		String firstName = mapa.get("firstName").toString();
		String lastName = mapa.get("lastName").toString();
		return firstName.substring(1,firstName.length()-1) + " " + lastName.substring(1,lastName.length()-1)
	}
	

}
